package com.smartcampusbackend.controller;

import com.smartcampusbackend.model.TitleApplication;
import com.smartcampusbackend.service.TitleApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class TitleApplicationController {
    @Autowired
    private TitleApplicationService titleApplicationService;

    // 教师提交职称申请
    @PostMapping("/users/me/title/apply")
    public ResponseEntity<String> applyForTitle(@RequestBody TitleApplication application) {
        String result = titleApplicationService.applyForTitle(application);
        return ResponseEntity.ok(result);
    }

    // 教师查询自己职称申请
    @GetMapping("/users/me/title/my-applications")
    public List<TitleApplication> getMyApplications(@RequestParam Integer teacherId) {
        return titleApplicationService.getMyApplications(teacherId);
    }

    // 管理员分页查询所有职称申请
    @GetMapping("/admin/titles")
    public List<Map<String, Object>> listTitleApplications(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        return titleApplicationService.listTitleApplications(page, size);
    }

    // 管理员审批职称申请
    @PutMapping("/admin/titles/{applicationId}/approve")
    public ResponseEntity<String> approveTitle(@PathVariable String applicationId) {
        String result = titleApplicationService.approveTitle(Long.valueOf(applicationId));
        return ResponseEntity.ok(result);
    }

    // 管理员拒绝职称申请
    @PutMapping("/admin/titles/{applicationId}/reject")
    public ResponseEntity<String> rejectTitle(
            @PathVariable String applicationId,
            @RequestBody String reason) {
        String result = titleApplicationService.rejectTitle(Long.valueOf(applicationId), reason);
        return ResponseEntity.ok(result);
    }
} 